package factoryProtocol;

import common.Payload;

public class Packet {
    public static final byte STX1 = (byte) 0xFE;
    public static final byte STX2 = (byte) 0xDC;
    public  byte version;
    public  byte[]  imei = new byte[6];
    public int session;   // 4个字节长度
    public byte  order = (byte) 0x03;   // 固定
    public int len = 0;   // 固定字节长度 24
    public Payload payload = null;   // 每4个字节合并成一个，如果温度是23.1的话 在报文中的表现是 00 00 00 e7，为231/10.0f
    public static final byte FCS = (byte) 0x00;  // 固定


    public void setPayloadLen(int payloadLength) {
        len = payloadLength;
        payload = new Payload(payloadLength);
    }

    public void cleanPayload() {
        payload.resetIndex();
    }

    public boolean payloadIsFilled() {
        return payload.size() >= len;
    }
}
